﻿using LdtJudge.DataEngine.CallInterface.CommHelp;
using LdtJudge.DataEngine.Model.DataModel.DataParseStorage;
using System.Collections.Generic;
using System.Linq;

namespace LdtJudge.DataEngine.Data.DataParseStorage
{
    /// <summary>
    /// 案件数据内容分析表
    /// </summary>
    public class DAL_An_shujuneirong
    {
        private IFreeSql FreeSql = FreeSQLHelp.GetFreeSQL("Ldt_DataParseStorage");
        /// <summary>
        /// 获取列表
        /// </summary>
        /// <param name="anjid">条件</param>
        /// <returns></returns>
        public List<An_shujuneirong> GetList(string anjianid)
        {
            return FreeSql.Select<An_shujuneirong>().Where(a => a.Anjianid == anjianid).ToList();
        }

        /// <summary>
        /// 查询当前卷宗信息是否存在
        /// </summary>
        /// <param name="shujuneirong"></param>
        /// <returns></returns>
        public List<An_shujuneirong> GetListWhere(An_shujuneirong shujuneirong)
        {
            return FreeSql.Select<An_shujuneirong>().Where(a => 
                        a.Anjianid == shujuneirong.Anjianid 
                        && a.Shujuyuanbianhao==shujuneirong.Shujuyuanbianhao
                        && a.Fl_id==shujuneirong.Fl_id
                        && a.Sf_id==shujuneirong.Sf_id).ToList();
        }
        /// <summary>
        /// 添加案件数据内容分析信息
        /// </summary>
        /// <param name="model">案件数据内容分析表模型</param>
        /// <returns></returns>
        public int Insert(An_shujuneirong model)
        {
            return FreeSql.Insert<An_shujuneirong>(model).ExecuteAffrows();
        }

        /// <summary>
        /// 判断当前数据源是否存在
        /// </summary>
        /// <param name="anjianid">案件ID</param>
        /// <param name="sf_id"></param>
        /// <param name="fl_id"></param>
        /// <returns></returns>
        public List<string> Exists(string anjianid, string sf_id, string fl_id)
        {
            List<An_shujuneirong> re = new List<An_shujuneirong>();
            re = FreeSql.Select<An_shujuneirong>().Where(a => a.Anjianid == anjianid && a.Sf_id == sf_id && a.Fl_id == fl_id)?.ToList();
            if (re != null && re.Count > 0)
                return re.Select(a => a.Shujuid).ToList();
            else
                return null;
        }

        /// <summary>
        /// 更新数据源状态
        /// </summary>
        /// <param name="state">状态值</param>
        /// <param name="shujvid">ID</param>
        /// <returns></returns>
        public int UpdateState(int state,string shujvid)
        {
            return FreeSql.Update<An_shujuneirong>().Set(a => a.Shujuyuanzhuangtai, state)
                .Where(a => a.Shujuid == shujvid)
                .ExecuteAffrows();
        }

        /// <summary>
        /// 更新案件数据内容分析表信息
        /// </summary>
        /// <param name="model">案件数据内容分析表模型</param>
        /// <returns></returns>
        public int Update(An_shujuneirong model)
        {
            return FreeSql.Update<An_shujuneirong>(model).SetSourceIgnore(model, col => col == null).ExecuteAffrows();
        }
    }
}
